package com.jit.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import androidx.annotation.Nullable;
import java.util.Timer;
import java.util.TimerTask;


public class FlashActivity extends Activity {

    public static final int FINISH_PLASH = 100;//关闭闪屏页面


    Handler handler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            switch (msg.what){
                case FINISH_PLASH:
                    finish();//关闭当前闪屏页
                    //开启下一个Activity
                    Class nextActivity = NavigationActivity.class;
                    boolean isNav = FlashActivity.this.getSharedPreferences("nav", MODE_PRIVATE).getBoolean("isNav",false);
                    if(isNav){
                        nextActivity = MainActivity.class;
                    }
                    Intent intent = new Intent(FlashActivity.this, nextActivity);
                    FlashActivity.this.startActivity(intent);
                    break;
            }
            return true;
        }
    });



    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.activity_flash);

    }

    @Override
    protected void onResume() {
        super.onResume();
        //三秒以后关闭
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                handler.sendEmptyMessage(FINISH_PLASH);
            }
        }, 3000);
    }
}
